package com.application.meizhi.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;

import com.application.meizhi.R;
import com.application.meizhi.model.douban.DouBanMeiZhi;
import com.application.meizhi.uitl.glideUtils.GlideImgManager;


import java.util.List;

import uk.co.senab.photoview.PhotoView;

/**
 * Created by gskl on 16/10/11.
 */

public class DouBanMeiZhiDetailAdapter extends PagerAdapter {

    private List<DouBanMeiZhi> mDatas;
    private Context mContext;

    public void update(List<DouBanMeiZhi> mDatas) {
        this.mDatas = mDatas;
        notifyDataSetChanged();
    }

    public DouBanMeiZhiDetailAdapter(List<DouBanMeiZhi> mDatas, Context mContext) {
        this.mDatas = mDatas;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public View instantiateItem(ViewGroup container, int position) {
        PhotoView photoView = new PhotoView(container.getContext());

        container.addView(photoView, ViewPager.LayoutParams.MATCH_PARENT, ViewPager.LayoutParams.MATCH_PARENT);
        GlideImgManager.glideLoader(mContext, mDatas.get(position).getUrl(), R.mipmap.ic_launcher, R.mipmap.ic_launcher, photoView);
        return photoView;
    }


    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

}
